﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.MobileControls;
using JsonServer.PowerDataSetTableAdapters;
namespace JsonServer
{
    public partial class MobilePage : MobilePage    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void ButtonCalculateMonthPower_Click(object sender, EventArgs e)
        {
            string year = this.TextBoxOfMonthPageYear.Text;
            string month = this.TextBoxOfMonthPageMonth.Text;
            string totalOneMonthPower = GetOneMonthPower(year, month);
            this.LabelMonthPower.Text = "Total one month power is " + totalOneMonthPower + "kW.";
        }

        public string GetOneMonthPower(string year, string month)
        {
            // lookup person with the requested id 
            PowerTableAdapter adap = new PowerTableAdapter();
            var powerTable = adap.GetDataByMonth(year, month);
            double MonthPower = 0;

            foreach (var item in powerTable)
            {
                double eachPower = item.Power;
                MonthPower += eachPower;
            }
            string sMonthPower = MonthPower.ToString("#.###0");
            return sMonthPower;
        }
    }
}